﻿@using Mrc.Application;
@{
    ViewData["Title"] = "LogList";
    Layout = "~/Areas/Admin/Views/_Layout.cshtml";

    var IsysService = ServiceHelper.GetService<ISysOrgService>(ViewContext.HttpContext);
    var list = IsysService.List(x => x.Id != string.Empty).ToList();
}

<link href="~/lib/layui/layui_ext/dtree/dtree.css" rel="stylesheet"/>
<link href="~/lib/layui/layui_ext/dtree/font/dtreefont.css" rel="stylesheet"/>

<table class="layui-hide" id="tabledata" lay-filter="tabledata"></table>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        @Html.Raw(Mrc.Application.PermissionButtonHelper.CreateButtonHtml(new List<string> { "system.user.add", "system.user.update", "system.user.delete", "system.user.revise_password"}, ViewContext.HttpContext));
        <button class="layui-btn layui-btn-sm" onclick="javascript:location.replace(location.href);">刷新</button>
    </div>
</script>
<script>

    /**/
    var orgName = $.parseJSON('@Html.Raw(ViewBag.orgName)');
    var postName = $.parseJSON('@Html.Raw(ViewBag.postName)');
    var roleName = $.parseJSON('@Html.Raw(ViewBag.roleName)');
    /**/
    layui.extend({
        dtree: '/lib/layui/layui_ext/dtree/dtree'
    }).use(['element', 'layer', 'dtree', 'form', 'table'], function () {
        var element = layui.element,
            layer = layui.layer,
            dtree = layui.dtree,
            form = layui.form,
            table = layui.table,
            $ = layui.$;
        table.render({
            elem: '#tabledata'
            , height: 'full-20'
            , url: '/admin/user/models'
            , toolbar: '#toolbarDemo'
            , title: 'IP过滤'
            , cols: [[
                { type: 'checkbox', fixed: 'left' }
                , { field: 'accountName', title: '登录账号', fixed: 'left',sort: true }
                , { field: 'name', title: '姓名',  sort: true }
                , { field: 'headIcon', title: '头像', sort: true }
                , { field: 'gender', title: '性别', unresize: true, sort: true }
                , { field: 'MobilePhone', title: '手机号', unresize: true, sort: true }
                , {
                    field: '', title: '部门',unresize: true, templet: function (res) {
                        return GetOrgName(res.orgIds);
                    }
                }
                , {
                    field: '', title: '岗位', unresize: true, templet: function (res) {
                        return GetPostName(res.postIds);
                    }
                }
                , {
                    field: '', title: '角色', unresize: true, templet: function (res) {
                        return GetRoleName(res.roleIds);
                    }
                }
                , {
                    field: 'createTime', title: '创建时间'
                }
                , { field: 'description', title: '描述' }
            ]]
            , limits: [10, 15, 40, 60, 80, 100, 200, 400]
            , limit: 100 //默认采用10
            , page: true
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
        });

        function GetOrgName(ids)
        {
            var names = '';
            if (ids == ""||ids==null) return "";
            var orgs = ids.split(",");
            for (var i = 0; i < orgs.length; i++)
            {
                names += orgName[orgs[i]]
            }
            return names;
        }
        function GetPostName(ids)
        {
            var names = '';
            if (ids == "" || ids == null) return "";
            var posts = ids.split(",");
            for (var i = 0; i < posts.length; i++) {
                names += postName[posts[i]]
            }
            return names;
        }
        function GetRoleName(ids)
        {
            var names = '';
            if (ids == "" || ids == null) return "";
            var Roles = ids.split(",");
            for (var i = 0; i < Roles.length; i++) {
                names += roleName[Roles[i]]
            }
            return names;
        }
        //头工具栏事件
        table.on('toolbar(tabledata)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add':
                    x_admin_show("添加用户信息", "/admin/user/add", 800, 550);
                    break;
                case 'update':
                    var data = checkStatus.data;
                    if (data.length > 1) {
                        layer.msg('请选择单个编辑项');
                        break;
                    }
                    else {

                        var thisline = data[0];
                        var id = thisline.id;
                        x_admin_show("修改用户信息", "/admin/user/update?Id=" + id, 800, 550);
                    }
                    break;
                case 'delete':
                    var data = checkStatus.data;
                    if (data.length > 1) {
                        layer.msg('请选择删除项');
                        break;
                    }
                    else
                    {
                        var ids = [];
                        for (var i = 0; i < data.length; i++) {
                            ids.push(data[i].id);
                        }
                        console.table(ids);
                        BaseAjax(ajaxType.post, "/admin/user/delete", { ids: ids }, function (repo) {
                            if (repo.status == ajaxStatus.OK) {
                                table.reload('tabledata', { page: { curr: 1 } });
                            }
                        });
                    }
                    break;

                case 'updatepassword':
                    var data = checkStatus.data;
                    if (data.length > 1) {
                        layer.msg('请选择单个编辑项');
                        break;
                    }
                    else {

                        var thisline = data[0];
                        var id = thisline.id;
                        x_admin_show("修改密码", "/admin/user/UpdatePassword?Id=" + id, 500, 350);
                    }
                    break;
                    break; 
                    
            };
        });
    })
</script>

